﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StockFinder.Forms;

namespace StockFinder
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            //load the IndexUrls form
            CreateIndexUrlForms();

            CreateSymbolListForms();

            CreateDownloadAllHistoricPricesForm();

            CreateJustBrokenOutTestForm();
        }

        private void CreateJustBrokenOutTestForm()
        {
            string formName = "JustBrokenOutTestForm";

            bool formExists = false;

            foreach (Form childForm in OwnedForms)
            {
                if (childForm.Name == formName)
                {
                    childForm.BringToFront();

                    formExists = true;
                }
            }

            if (!formExists)
            {
                HasJustBrokenOutTestForm form = new HasJustBrokenOutTestForm();
                form.Name = formName;
                this.AddOwnedForm(form);

                form.MdiParent = this;

                form.Show();
            }
        }

        private void CreateDownloadAllHistoricPricesForm()
        {
            string formName = "DownloadAllHistoricPricesForm";

            bool formExists = false;

            foreach (Form childForm in OwnedForms)
            {
                if (childForm.Name == formName)
                {
                    childForm.BringToFront();

                    formExists = true;
                }
            }

            if (!formExists)
            {
                DownloadAllHistoricPricesForm form = new DownloadAllHistoricPricesForm();
                form.Name = formName;
                this.AddOwnedForm(form);

                form.MdiParent = this;

                form.Show();
            }
        }

        private void CreateSymbolListForms()
        {
            string formName = "SymbolListForm";

            bool formExists = false;

            foreach (Form childForm in OwnedForms)
            {
                if (childForm.Name == formName)
                {
                    childForm.BringToFront();

                    formExists = true;
                }
            }

            if (!formExists)
            {
                SymbolsManager form = new SymbolsManager();
                form.Name = formName;
                this.AddOwnedForm(form);

                form.MdiParent = this;

                form.Show();
            }
        }

        private void CreateIndexUrlForms()
        {
            string formName = "UrlListForm";

            bool formExists = false;

            foreach (Form childForm in OwnedForms)
            {
                if (childForm.Name == formName)
                {
                    childForm.BringToFront();

                    formExists = true;
                }
            }

            if (!formExists)
            {
                UrlListForm form = new UrlListForm();
                form.Name = formName;
                this.AddOwnedForm(form);

                form.MdiParent = this;

                form.Show();
            }            
        }
    }
}
